﻿
using System;
using System.Web.Helpers;
using MMSWebsite.Models;

namespace MMSWebsite.HtmlHepler
{
    public class WebMailHelper
    {
        public static void SendPassword(string toEmail, string username, string code, string password)
        {
            WebMail.SmtpServer = "smtp.gmail.com";
            WebMail.SmtpPort = 587;
            WebMail.EnableSsl = true;
            WebMail.UserName = "trongnghia206@gmail.com";
            WebMail.Password = "mrvitxiem";
            WebMail.From = "trongnghia206@gmail.com";
            string content = "Hi <strong>" + username + "</strong>. <br/>NBK Bank system has just reset your password with your code " + code + 
                ". <br/>Your new password is <strong>" + password + "</strong>. Please log in by new password to test and don't forget it. <br/> " +
                "If having any questions, please contact email NBKBank@bank.com.vn";
            string template = ReturnHtmlEmail(content);
            WebMail.Send(toEmail, "Password for you from MMS Website", template);
        }

        public static void SendCaseToFV(EmployeeViewModel fv, EmployeeViewModel reviewer,  Customer customer)
        {
            WebMail.SmtpServer = "smtp.gmail.com";
            WebMail.SmtpPort = 587;
            WebMail.EnableSsl = true;
            WebMail.UserName = "trongnghia206@gmail.com";
            WebMail.Password = "mrvitxiem";
            WebMail.From = "trongnghia206@gmail.com";
            TimeSpan time = (TimeSpan) (customer.EndDay - customer.StartDay);
            string content = "Hi <strong>" + fv.Employee.Name + "</strong>. <br/>" +
                             "You have just allocated Customer <strong>" + customer.Name +
                             "</strong> by your Reiviewer <strong>" + reviewer.Employee.Name + "</strong>.<br>"
                             + "Your time is " + time.Days + " days from <strong>" + customer.StartDay.Value.ToShortDateString() +
                             "</strong> to <strong>" + customer.EndDay.Value.ToShortDateString() + "</strong>.<br>" +
                             "If you have any idea or want to change something about this case, please contact your Reviewer with email : <strong>" +
                             reviewer.Employee.Email + "</strong>. <br> Have nice day! Sincerely.";
            string template = ReturnHtmlEmail(content);
            WebMail.Send(fv.Employee.Email, "You have just allocated Customers", template);
        }

        public static void SendFinishLoan(EmployeeViewModel fv, EmployeeViewModel reviewer, Customer customer)
        {
            WebMail.SmtpServer = "smtp.gmail.com";
            WebMail.SmtpPort = 587;
            WebMail.EnableSsl = true;
            WebMail.UserName = "trongnghia206@gmail.com";
            WebMail.Password = "mrvitxiem";
            WebMail.From = "trongnghia206@gmail.com";
            string content = "Hi <strong>" + fv.Employee.Name + "</strong>. <br/>" +
                             "Your customer is <strong>" + customer.Name + "</strong> with <strong>Code: " + customer.Code +
                             "</strong> " +
                             "Who has been loaned by your reviewer <strong>" + reviewer.Employee.Name + "</strong>. <br>" +
                             "Please check it out again and remember to confirm your customer's idea.<br>" + 
                             "Any problem, please contact your reviewer with email: " + reviewer.Employee.Email;
            string template = ReturnHtmlEmail(content);
            WebMail.Send(fv.Employee.Email, "Notice: Your customer has been loaned all asset.", template);
        }

        //don't look, terrible
        public static string ReturnHtmlEmail(string content)
        {
            string template = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' >" +
"<html>" +
    "<head>" +
        "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />" +

        "<meta property='og:title' content='*|MC:SUBJECT|*' />" +

        "<title>*|MC:SUBJECT|*</title>" +
        "<style type='text/css'>" +
            "/* Client-specific Styles */" +
            "#outlook a{padding:0;} /* Force Outlook to provide a 'view in browser' button. */" +
            "body{width:100% !important;} .ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */" +
            "body{-webkit-text-size-adjust:none;} /* Prevent Webkit platforms from changing default text sizes. */" +

            "/* Reset Styles */" +
            "body{margin:0; padding:0;}" +
            "img{border:0; height:auto; line-height:100%; outline:none; text-decoration:none;}" +
            "table td{border-collapse:collapse;}" +
            "#backgroundTable{height:100% !important; margin:0; padding:0; width:100% !important;}" +

            "body, #backgroundTable{ background-color:#FAFAFA;}" +
            "#templateContainer{border: 1px solid #DDDDDD;}" +


            "h1, .h1{ " +
                "/*@editable*/ color:#202020;" +
                "display:block;" +
                "/*@editable*/ font-family:Arial;" +
                "/*@editable*/ font-size:34px;" +
                "/*@editable*/ font-weight:bold;" +
                "/*@editable*/ line-height:100%;" +
                "margin-top:0;margin-right:0;margin-bottom:10px;margin-left:0;/*@editable*/ text-align:left;}" +

            "h2, .h2{" +
                "/*@editable*/ color:#202020;display:block;" +
                "/*@editable*/ font-family:Arial;/*@editable*/ font-size:30px;/*@editable*/ font-weight:bold;/*@editable*/ line-height:100%;" +
                "margin-top:0;margin-right:0;margin-bottom:10px;margin-left:0;/*@editable*/ text-align:left;}" +

            "h3, .h3{ " +
                "/*@editable*/ color:#202020;display:block;" +
                "/*@editable*/ font-family:Arial;/*@editable*/ font-size:26px;/*@editable*/ font-weight:bold;/*@editable*/ line-height:100%;" +
                "margin-top:0;margin-right:0;margin-bottom:10px;margin-left:0;/*@editable*/ text-align:left;}" +

            "h4, .h4{" +
                "/*@editable*/ color:#202020;display:block;" +
                "/*@editable*/ font-family:Arial;/*@editable*/ font-size:22px;/*@editable*/ font-weight:bold;/*@editable*/ line-height:100%;" +
                "margin-top:0;margin-right:0;margin-bottom:10px;margin-left:0;/*@editable*/ text-align:left;}" +

            "#templatePreheader{ background-color:#FAFAFA;}" +

            ".preheaderContent div{/*@editable*/ color:#505050;/*@editable*/ font-family:Arial;/*@editable*/ font-size:10px;/*@editable*/ line-height:100%;/*@editable*/ text-align:left;}" +

            ".preheaderContent div a:link, .preheaderContent div a:visited, /* Yahoo! Mail Override */ .preheaderContent div a .yshortcuts /* Yahoo! Mail Override */{" +
                "/*@editable*/ color:#336699;/*@editable*/ font-weight:normal;/*@editable*/ text-decoration:underline;}" +

            "#templateHeader{/*@editable*/ background-color:#FFFFFF;/*@editable*/ border-bottom:0;}" +

            ".headerContent{" +
                "/*@editable*/ color:#202020;/*@editable*/ font-family:Arial;/*@editable*/ font-size:34px;/*@editable*/ font-weight:bold;" +
                "/*@editable*/ line-height:100%;/*@editable*/ padding:0;/*@editable*/ text-align:center;/*@editable*/ vertical-align:middle;}" +

            ".headerContent a:link, .headerContent a:visited, /* Yahoo! Mail Override */ .headerContent a .yshortcuts /* Yahoo! Mail Override */{" +
            "/*@editable*/ color:#336699;/*@editable*/ font-weight:normal;/*@editable*/ text-decoration:underline;}" +

            "#headerImage{height:auto;max-width:600px !important;}" +

            "#templateContainer, .bodyContent{/*@editable*/ background-color:#FFFFFF;}" +

            ".bodyContent div{" +
            "/*@editable*/ color:#505050;/*@editable*/ font-family:Arial;/*@editable*/ font-size:14px;/*@editable*/ line-height:150%;/*@editable*/ text-align:left;}" +

            ".bodyContent div a:link, .bodyContent div a:visited, /* Yahoo! Mail Override */ .bodyContent div a .yshortcuts /* Yahoo! Mail Override */{" +
            "/*@editable*/ color:#336699;/*@editable*/ font-weight:normal;/*@editable*/ text-decoration:underline;}" +

            ".bodyContent img{display:inline;height:auto;}" +

            "#templateFooter{/*@editable*/ background-color:#FFFFFF;/*@editable*/ border-top:0;}" +

            ".footerContent div{" +
            "/*@editable*/ color:#707070;/*@editable*/ font-family:Arial;/*@editable*/ font-size:12px;/*@editable*/ line-height:125%;/*@editable*/ text-align:left;}" +

            ".footerContent div a:link, .footerContent div a:visited, /* Yahoo! Mail Override */ .footerContent div a .yshortcuts /* Yahoo! Mail Override */{" +
            "/*@editable*/ color:#336699;/*@editable*/ font-weight:normal;/*@editable*/ text-decoration:underline;}" +

            ".footerContent img{display:inline;}" +

            "#social{/*@editable*/ background-color:#FAFAFA;/*@editable*/ border:0;}" +

            "#social div{/*@editable*/ text-align:center;}" +

            "#utility{/*@editable*/ background-color:#FFFFFF;/*@editable*/ border:0;}" +

            "#utility div{/*@editable*/ text-align:center;}" +

            "#monkeyRewards img{max-width:190px;}" +
            "</style>" +
            "</head>" +
            "<body leftmargin='0' marginwidth='0' topmargin='0' marginheight='0' offset='0'>" +
            "<center>" +
            "<table border='0' cellpadding='0' cellspacing='0' height='100%' width='100%' id='backgroundTable'>" +
            "<tr>" +
            "<td align='center' valign='top'>" +
            "<!-- // Begin Template Preheader \\ -->" +
            "<table border='0' cellpadding='10' cellspacing='0' width='600' id='templatePreheader'>" +
            "<tr>" +
            "<td valign='top' class='preheaderContent'>" +


            "<table border='0' cellpadding='10' cellspacing='0' width='100%'>" +
            "<tr>" +
            "<td valign='top'>" +
            "<div mc:edit='std_preheader_content'>" +
            "Use this area to offer a short teaser of your email's content. Text here will show in the preview area of some email clients." +
            "</div>" +
            "</td>" +

            "<td valign='top' width='190'>" +
            "<div mc:edit='std_preheader_links'>" +
            "Is this email not displaying correctly?<br /><a href='*|ARCHIVE|*' target='_blank'>View it in your browser</a>." +
            "</div>" +
            "</td>" +

            "</tr>" +
            "</table>" +


            "</td>" +
            "</tr>" +
            "</table>" +

            "<table border='0' cellpadding='0' cellspacing='0' width='600' id='templateContainer'>" +
            "<tr>" +
            "<td align='center' valign='top'>" +
            "<!-- // Begin Template Header \\ -->" +
            "<table border='0' cellpadding='0' style='box-shadow: 0px 1px 1px 1px black' cellspacing='0' width='600' id='templateHeader'>" +
            "<tr>" +
            "<td class='headerContent'>" +

            "<!-- // Begin Module: Standard Header Image \\ -->" +
            "<img src='http://i1012.photobucket.com/albums/af250/pippopboy/logo.png' style='max-width:600px;' id='headerImage campaign-icon' mc:label='header_image' mc:edit='header_image' mc:allowdesigner mc:allowtext />" +
            "<!-- // End Module: Standard Header Image \\ -->" +

            "</td>" +
            "</tr>" +
            "</table>" +
            "<!-- // End Template Header \\ -->" +
            "</td>" +
            "</tr>" +
            "<tr>" +
            "<td align='center' valign='top'>" +
            "<!-- // Begin Template Body \\ -->" +
            "<table border='0' cellpadding='0' cellspacing='0' width='600' style='background-color: gray;' id='templateBody'>" +
            "<tr>" +
            "<td valign='top' class='bodyContent'>" +

            "<!-- // Begin Module: Standard Content \\ -->" +
            "<table border='0' cellpadding='20' style='box-shadow: 0px 2px 3px 0px black' cellspacing='0' width='100%'>" +
            "<tr>" +
            "<td valign='top'>" +
            "<div mc:edit='std_content00'>" +

            content +//content hereeeeeeeeeeeeeeee

            "</div>" +
            "</td>" +
            "</tr>" +
            "</table>" +
            "<!-- // End Module: Standard Content \\ -->" +

            "</td>" +
            "</tr>" +
            "</table>" +
            "<!-- // End Template Body \\ -->" +
            "</td>" +
            "</tr>" +
            "<tr>" +
            "<td align='center' valign='top'>" +
            "<!-- // Begin Template Footer \\ -->" +
            "<table border='0' style='box-shadow: 0px 2px 3px 0px black' cellpadding='10' cellspacing='0' width='600' id='templateFooter'>" +
            "<tr>" +
            "<td valign='top' class='footerContent'>" +

            "<!-- // Begin Module: Standard Footer \\ -->" +
            "<table border='0' cellpadding='10' cellspacing='0' width='100%'>" +
            "<tr>" +
            "<td colspan='2' valign='middle' id='social'>" +
            "<div mc:edit='std_social'>" +
            "<strong>Design by Cao Trần Trọng Nghĩa</strong>, follow me with this link on Facebook <a href='http://www.facebook.com/cao.kenny?ref=tn_tnmn'>Kenny Cao </a> for more information about system. " +
            "</div>" +
            "</td>" +
            "</tr>" +
            "<tr>" +
            "<td valign='top' width='350'>" +
            "<div mc:edit='std_footer'>" +
            "<em>Copyright &copy; NBK Bank System 2012, All right Reserved" +
            "<br />" +
            "<strong>Our mailing address is:</strong>" +
            "<br />" +
            "<strong>BNKBank@bank.com.vn" + " or trongnghia206@gmail.com</strong>" +
            "</div>" +
            "</td>" +
            "<td valign='top' width='190' id='monkeyRewards'>" +
            "<div mc:edit='monkeyrewards'>" +
            "NBK Bank : Giải Nhất Ngân Hàng Uy Tín, Chất Lượng hoàn hảo năm 2012 " +
            "</div>" +
            "</td>" +
            "</tr>" +
            "<tr>" +
            "<td colspan='2' valign='middle' id='utility'>" +
            "<div mc:edit='std_utility'>" +
            "&nbsp;<a href='*|UNSUB|*'>unsubscribe from this list</a> | <a href='*|UPDATE_PROFILE|*'>update subscription preferences</a>&nbsp;" +
            "</div>" +
            "</td>" +
            "</tr>" +
            "</table>" +
            "<!-- // End Module: Standard Footer \\ -->" +

            "</td>" +
            "</tr>" +
            "</table>" +
            "<!-- // End Template Footer \\ -->" +
            "</td>" +
            "</tr>" +
            "</table>" +
            "<br />" +
            "</td>" +
            "</tr>" +
            "</table>" +
            "</center>" +
            "</body>" +
            "</html>'" + "";

            return template;
        }
    }
}